<template>
  <div class="ran_cell">
    <img :src="'/companys/' + ranPic" @click="gotoPro(item.pid)" alt="" />
    <div class="sm_card">
      <span>{{ item.pname }}</span>
      <div>
        <div>
          <span>￥</span>
          <h3>{{ item.price }}</h3>
        </div>
        <span>100%好评</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    gotoPro(pid) {
      //   console.log(this.$route)
      window.scrollTo(0, 0)
      const path = "/pro_details?pid=" + pid
      if (this.$route.fullPath === path) {
        // this.$router.go(0)

        return
      }
      this.$router.push(path)
    },
  },
  computed: {
    ranPic() {
      let pics = this.item.pics.split("=")
      let i = Math.floor(Math.random() * pics.length)
      return pics[i]
    },
  },
  props: {
    item: {
      required: true,
    },
  },
}
</script>

<style lang="scss" scoped>
.ran_cell {
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 60px;
  > img {
    width: 100%;
    border-radius: 5px;
    cursor: pointer;
    &:hover {
      opacity: 0.8;
    }
  }
  .sm_card {
    width: 80%;
    margin: 0 auto;
    box-shadow: -5px 5px 10px -4px #f0f0f0, 5px 5px 10px -4px #f0f0f0;
    position: absolute;
    bottom: -40px;
    background-color: #fff;
    border-radius: 5px;
    transition: 0.3s;
    &:hover {
      bottom: -30px;
    }
    > span {
      width: 90%;
      display: block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin: 15px auto;
    }
    > div {
      display: flex;
      justify-content: space-between;
      width: 90%;
      margin: 0 auto 20px;
      align-items: center;
      > div {
        display: flex;
        color: #e4464b;
        align-items: center;
        > span {
          font-size: 16px;
        }
      }
      > span {
        font-size: 12px;
      }
    }
  }
}
</style>
